<?php

namespace admin;

use models\BaseDao;

class Index extends Admin{
    function __construct(){
        $this->assign('menumark','product');//前端分类标题点击 标记位
        parent::__construct();
    }
    function index(){

        $db = new BaseDao();

        $this->assign('title','后台首页');

        $tongji = [];
        // 商品统计
        // 上架商品
        $tongji['product_up'] = $db->count('product',['state'=>1]);
        // 下架商品
        $tongji['product_down'] = $db->count('product',['state'=>0]);
        // 缺货商品
        $tongji['product_empty'] = $db->count('product',['state'=>1,'num[<]'=>1]);
        // 推荐商品
        $tongji['product_tuijian'] = $db->count('product',['state'=>1,'istuijian'=>1]);


        // 访客统计
        $today = strtotime(date('Y-m-d'));
        $yesterday = strtotime(date('Y-m-d',strtotime('-1 day')));
        
        // 今日访客
        $tongji['iplog_today'] = $db->count('iplog',['atime[>=]'=>$today]);
        // 昨日访客
        $tongji['iplog_lastday'] = $db->count('iplog',['atime[>=]'=>$yesterday,'atime[<]'=>$today]);

        // 累计访客
        $tongji['iplog_all'] = $db->count('iplog');
        // 所有注册用户
        $tongji['iplog_user'] = $db->count('user');


        // 交易数据
        // 今日订单
        $tongji['order_today'] = $db->count('order',['atime[>=]'=>$today]);
        $money_today = $db->sum('order','productmoney',['atime[>=]'=>$today]);

        $tongji['money_today'] = number_format($money_today,2,'.','');

        // 昨日订单
        $tongji['order_lastday'] = $db->count('order',['atime[>=]'=>$yesterday,'atime[<]'=>$today]);
        $money_lastday = $db->sum('order','productmoney',['atime[>=]'=>$yesterday,'atime[<]'=>$today]);
        
        $tongji['money_lastday'] = number_format($money_lastday,2,'.','');

       // 全部订单
       $tongji['order_all'] = $db->count('order');
       $money_all = $db->sum('order','productmoney');
       $tongji['money_all'] = number_format($money_all,2,'.','');

        $this->assign($tongji);

        $this->display("index/index");
   
    }

}
